<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache"/>   
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate"/>   
<meta http-equiv="expires" content="0"/>  
<title>APP封面设置</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/select.css" rel="stylesheet" type="text/css" />
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/jquery.idTabs.min.js"></script>
<script type="text/javascript" src="js/select-ui.min.js"></script>
<script type="text/javascript" src="editor/kindeditor.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>

<script type="text/javascript">


	var serviceTelData = null;

	$(document).ready(function(e) {
		$("#btnSave").click(updateServiceTel);
		loadServiceTel();//加载服务热线
		$("#uploadFile").change(uploadSpaceImage);
	});
	function uploadSpaceImage(){
		
		var fileName = $("#uploadFile").val();
		
		 var dom = document.getElementById("uploadFile");
		 var fileSize = dom.files[0].size;
		 if (fileSize > 10000000) {
			 alert("上传文件过大,请上传小于10M的图片");
			 $("#uploadFile").val("");
			 return false;
		}
		var fileType = fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length).toLocaleLowerCase();
		if (fileType != 'jpg' && fileType != 'bmp' && fileType != 'png' && fileType != 'gif' && fileType != "jpeg") {
			alert("图片只能上传JPG,JPEG,BMP,PNG,GIF格式的图片！");
			$("#uploadFile").val("");
			return false;
		}
		
		var accessToken = localStorage.getItem('accessToken');
		$('#noticeImageForm').ajaxSubmit({
			dataType : "json",
			headers : {'Access-Control-Allow-Origin':'*',"accessToken":accessToken},
			beforeSubmit : function(request) { 
				//alert("正在上传"); 
			}, 
			success : function(result, textStatus, response) { 
				//alert(JSON.stringify(result));
				$("#noticeImage").attr("src",result.fileUrl);
				$("#wechat").val(result.fileUrl);
				//alert('成功上传！'); 		 
			},
			error : function(result) {
				//alert('上传失败！'); 
			} 
		});
	}
	function loadServiceTel(){
		var requestJson = {data:{"id":2}}
		$.ajax({
	        url: '/euc/onlineops/tel/detail',
	        data:JSON.stringify(requestJson),
	        beforeSend: function(request) {
	        	var accessToken = localStorage.getItem('accessToken');
	            request.setRequestHeader("accessToken",accessToken );
	        },
	        dataType: 'JSON',
	        async: true,
	        contentType:'application/json;charset=utf-8',
	        type: 'POST',
	        success: function (result, textStatus, response) {
	        	if(result.status == '0'){
	        		var data = result.data;
	        		//$("input[name='tel']").val(data.tel);
	        		if(data.wechat){
	        			$("input[name='wechat']").val(data.wechat);
	        			$("#noticeImage").attr('src',data.wechat);
	        			
	        		}
	        		
	        		serviceTelData = data;
	        	}else{
	        		serviceTelData = null;
	        		alert(resutl.message);
	        	}
	        },
	        error: function () {
	        	serviceTelData = null;
	        	console.log("/euc/onlineops/tel/detail error");
	        }
	    });
	}
	
	function updateServiceTel(){
		if(serviceTelData == null){
			return;
		}
		var wechat = $.trim($("input[name='wechat']").val());
		if(wechat == ''){
			alert("请输入图片地址！");
			return;
		}
		serviceTelData["id"] = 2;
		serviceTelData["tel"] = '';
		serviceTelData["wechat"] = wechat;
		var requestJson = {data:serviceTelData}
		$.ajax({
	        url: '/euc/onlineops/tel/edit',
	        data:JSON.stringify(requestJson),
	        beforeSend: function(request) {
	        	var accessToken = localStorage.getItem('accessToken');
	            request.setRequestHeader("accessToken",accessToken );
	        },
	        dataType: 'JSON',
	        async: true,
	        contentType:'application/json;charset=utf-8',
	        type: 'POST',
	        success: function (result, textStatus, response) {
	        	if(result.status == '0'){
	        		var data = result.data;
	        		//$("input[name='tel']").val(data.tel);
	        		$("input[name='wechat']").val(data.wechat);
	        		$("#noticeImage").attr('src',data.wechat);
	        		serviceTelData = data;
	        		alert("保存成功！");
	        	}else{
	        		alert(resutl.message);
	        	}
	        },
	        error: function () {
	        	console.log("/euc/onlineops/tel/detail edit");
	        }
	    });
	}

</script>




</head>

<body>

	<div class="place">
    	<span>位置：</span>
    	<ul class="placeul">
		    <li><a href="#">线上运营管理</a></li>
		    <li><a href="#">APP封面图片</a></li>
    	</ul>
    </div>

    <div class="formbody">	    
	    <div class="formtitle"><span>APP封面图片设置</span></div>	    
	    <ul class="forminfo">
   
		    <li></li>		    
		    <li>
				<label style="font-size:16px;float:left;width:140px;">封面（推荐尺寸1000*600）<b>*</b></label>
			    <span><img style="width:400px;height:240px;"  name="activityImage" id="noticeImage" src="images/img07.png" onerror="this.src='images/img07.png'"/></span>
			    <input  name="wechat" id="wechat" formParameter="notice"   type="hidden" value=""/>
		    </li>
		    <li>
				<label style="font-size:16px;float:left;width:140px;">&nbsp;</b></label>
				<form style="float:left;" id="noticeImageForm" action="/euc/system/upload" method="post" enctype="multipart/form-data">
			    	<input id="uploadFile"   name="file" type="file" style="width:400px;" value="添加图片"/>
			    	<input  name="folderName" type="hidden" value="notice"/>
			    	<input  name="fileType" type="hidden" value="图片"/>
			    </form>
		    </li>   
		    <li></li>
		    <li>
		    	<label>&nbsp;</label>
		    	<input name="btnSave"  id="btnSave"  type="button" class="btn" value="确定"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		    </li> 
	    </ul>
    </div>
</body>
</html>
